namespace Controller.Pizza;

using Microsoft.AspNetCore.Mvc;
using Model.Pizza;

/// <summary>
/// 在此可以可选开启CORS，也可在Program中开启
/// </summary>
// [EnableCors("any")]
[ApiController]// 禁用后可以使swagger输入从字符串自由输入变为限定值的输入
[Route("api/[controller]/[action]")]
public class PizzaController : Controller
{
    [HttpGet("{i}")]
    // [NonAction]
    public string Get1(int i)
    {
        // HttpResponseMessage res = new();
        // res.Headers.Add("content-type", "text/html");
        // HttpWebRequest req = (HttpWebRequest)WebRequest.Create()
        // Console.WriteLine(id);
        return "i is " + i.ToString();
    }

    [HttpGet]
    public IActionResult Get2()
    {
        return Ok();
    }
    [HttpGet]
    public ActionResult<Pizza> Get3()
    {
        return new Pizza { Id = 12, Name = "fjikjfs", Price = 342 };
    }
    [HttpGet]
    public IActionResult Get4(int id)
    {
        Pizza pizza = Pizza.GetByID(id);
        return Ok(pizza);
    }
    [HttpPost]
    public ActionResult<Pizza> Post1(Pizza pizza)
    {
        Pizza.pizzas.Add(pizza);
        return pizza;
    }
    [HttpPost]
    public Pizza Post2(Pizza data)
    {
        // return data.Id + data.Name + data.Price;
        return data;
    }
    [HttpDelete("{id}")]
    public string Delete1(int id)
    {
        Pizza? pizza = Pizza.GetByID(id);
        Pizza.pizzas.Remove(pizza);
        return "Deleted!";
    }
}
